package org.springframework.validation.util;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.webflow.execution.RequestContext;

public class WebflowVariableResolver extends ModelAndMapsVariableResolver {
	
	public static final String REQUEST_SCOPE = "requestScope";
	public static final String FLASH_SCOPE = "flashScope";
	public static final String VIEW_SCOPE = "viewScope";
	public static final String FLOW_SCOPE = "flowScope";
	public static final String CONVERSATION_SCOPE = "conversationScope";
	public static final String REQUEST_PARAMETERS = "requestParameters";
	public static final String REQUEST_ATTRIBUTES = "requestAttributes";
	public static final String SESSION = "session";
	
	@SuppressWarnings("unchecked")
	public WebflowVariableResolver(RequestContext rc, Object model) {
		super(model); // hurr.
		addMapContext(REQUEST_SCOPE, rc.getRequestScope().asMap());
		addMapContext(FLASH_SCOPE, rc.getFlashScope().asMap());
		addMapContext(VIEW_SCOPE, rc.getViewScope().asMap());
		addMapContext(FLOW_SCOPE, rc.getFlowScope().asMap());
		addMapContext(CONVERSATION_SCOPE, rc.getConversationScope().asMap());
		addMapContext(REQUEST_PARAMETERS, rc.getRequestParameters().asMap());
		addMapContext(REQUEST_ATTRIBUTES, rc.getExternalContext().getRequestMap().asMap());
		addMapContext(SESSION, rc.getExternalContext().getSessionMap().asMap());		
	}
}
